package main.java.FSMDE.models;

import java.util.UUID;

import main.java.ERMDE.models.INameable;
import main.java.ERMDE.models.IStrongEntity;


public class Interface implements INameable, IStrongEntity {

	private String name;
	private UUID id;
	private InterfaceType type;
	private ComponentCollection components;
	private TransitionCollection transitions; // this shouldn[t be here!!
	private InterfaceGraphType graphType;
	private String subDiagramName;

	public Interface(UUID interfaceId, String interfaceName,
			InterfaceType interfaceType, TransitionCollection transitions,
			InterfaceGraphType interfaceGraphType) {
		name = interfaceName;
		id = interfaceId;
		type = interfaceType;
		graphType = interfaceGraphType;
		components = new ComponentCollection();
		this.transitions = transitions;
		this.subDiagramName = "";
	}

	public Interface(String interfaceName, InterfaceType interfaceType,
			InterfaceGraphType interfaceGraphType) {
		name = interfaceName;
		id = UUID.randomUUID();
		type = interfaceType;
		graphType = interfaceGraphType;
		components = new ComponentCollection();
		this.subDiagramName = "";
		this.transitions = new TransitionCollection();
	}

	public Interface(String interfaceName) {
		name = interfaceName;
		id = UUID.randomUUID();
		type = InterfaceType.General;
		graphType = InterfaceGraphType.Normal;
		components = new ComponentCollection();
		this.subDiagramName = "";
		this.transitions = new TransitionCollection();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public UUID getId() {
		return id;
	}

	public void setId(UUID id) {
		this.id = id;
	}

	public InterfaceType getType() {
		return type;
	}

	public void setType(InterfaceType type) {
		this.type = type;
	}

	public ComponentCollection getComponents() {
		return components;
	}

	public void setComponents(ComponentCollection components) {
		this.components = components;
	}

	@Override
	public String toString() {
		return this.name;
	}

	public TransitionCollection getTransitions() {
		return this.transitions;
	}

	public void setTransitions(TransitionCollection transcol) {
		for (Transition trans : transcol) {
			this.transitions.add(trans);
		}
	}

	public void setGraphType(InterfaceGraphType graphType) {
		this.graphType = graphType;
	}

	public InterfaceGraphType getGraphType() {
		return this.graphType;
	}

	public void setSubDiagram(String diagramName) {
		this.subDiagramName = diagramName;
	}

	public String getRelatedSubdiagramName() {
		return this.subDiagramName;
	}

	public boolean hasSubDiagram() {
		return (!this.subDiagramName.equals(""));
	}

	public Component getComponent(String componentId) {
		for (Component component : this.getComponents()) {
			if (component.getId().toString().equals(componentId)) {
				return component;
			}
		}
		return null;
	}
}
